<?php

/**
 * 
 * @author yuxun
 *
 */
class TmscService extends Service{

    public static function sHeader(){
        $header = array(
            'name'          => array('text' => '标识', 'width' => '150px'),
        	'show_name'     => array('text' => '服务器名称', 'width' => '150px'),
        	'server_id'     => array('text' => '服务器ID', 'width' => '150px'),
            'show_status'   => array('text' => '表现状态', 'width' => '100px'),
        	'ip'            => array('text' => 'IP地址', 'width' => '100px'),
        	'port'          => array('text' => '端口', 'width' => '100px'),
        	'float_status'  => array('text' => '漂浮窗状态', 'width' => '100px'),
        	'open_time'     => array('text' => '开服时间', 'width' => '160px'),
        	'action'        => array('text' => '操作', 'width' => '160px'),
        );

        return $header;
    }

    public static function sData($params){
    	$params = array();
    	$api = new ApiSynchro();
    	$result = $api->gameAll($params);
    	if(!$result['state']){
    		return $result;
    	}else {
    		$showStatusList = ServerService::showStatusList();
    		foreach($result['data'] as &$v){
    			$v['show_status'] = $showStatusList[$v['show_status']];
    			$v['open_time'] = date('Y-m-d H:i:s',$v['open_time']);
    			$v['action'] = ' <a href="'.PubFunc::buildUrl('/oss/?r=tmsc/edit').'&name='.$v['name'].'">编辑</a>';
    			//$v['action'] .= ' <a href="'.PubFunc::buildUrl('/oss/?r=tmsc/delete').'&name='.$v['name'].'" confirm="是否要删除该条服信息?">删除</a>';
    		}
    		unset($v);
    		return $result;
    	}
    }
    
    public static function sdoAdd($params){
    	if(PubFunc::checkEmpty($params, array( 'name', 'show_status','ip','port','float_status','open_time'))){
    		return array('state' => false, 'msg' => '缺少必要参数.');
    	}
    	
    	unset($params['m']);
    	unset($params['g']);
    	unset($params['p']);
    	unset($params['sub']);
    	
    	$params['open_time'] = strtotime($params['open_time']);
    
    	$api = new ApiSynchro();
    	$result = $api->gameAdd($params);
    	if($result['state']){
    		return array('state' => $result, 'msg' =>'添加成功');
    	}else{
    		return array('state' => false, 'msg' => $result['msg']);
    	}
    	 
    }
    
    public static function sget($name){
    	if(empty($name)) return false;
    	
    	$api = new ApiSynchro();
    	$result = $api->gameGet($name);
    }
    
    
    
    public static function cHeader(){
    	$header = array(
    			'channel_id'    => array('text' => '渠道ID', 'width' => '150px'),
    			'game_list'     => array('text' => '服务器列表', 'width' => '300px'),
    			'action'        => array('text' => '操作', 'width' => '160px'),
    	);
    
    	return $header;
    }
    
    public static function cData($params){
    	$params = array();
    	$api = new ApiSynchro();
    	$result = $api->channelAll($params);
    	if(!$result['state']){
    		return $result;
    	}else {
    		foreach($result['data'] as &$v){
    			$v['action'] = ' <a href="'.PubFunc::buildUrl('/oss/?r=tmsc/edit').'&name='.$v['name'].'">编辑</a>';
    			$game_list = '';
    			foreach ($v['game_list'] as $key=>$val){
    				$game_list .= ','.$val;
    			}
    			$v['game_list'] = substr($game_list, 1);
    		}
    		unset($v);
    		return $result;
    	}
    }
    
    
    
}